/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.zbxsoft.portal.tags  
 */
package com.dwusoft.platform.template;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.apache.cache.util.Validator;

/**
 * description:  自定义定义变量
 * @author Hou Dayu 创建时间：2015-8-24  
 * 
 */
@SuppressWarnings("serial")
public class SetStringTag extends TagSupport {

	private String var;// 当前变量名
	private String value; // 变量值
	private String varType;//变量类型(int,float,String)
	private String spacer = ",";//当前值
	private String prefix = "";

	public int doStartTag() throws JspException {
		boolean b = false;
		try {
			HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
			String nowVarValue = String.valueOf(request.getAttribute(var));
			if ("int".equals(varType)) {
				if (Validator.isNull(nowVarValue))
					nowVarValue = "0";
				nowVarValue = String.valueOf(Integer.valueOf(nowVarValue) + Integer.valueOf(value));
			} else if ("float".equals(varType)) {
				if (Validator.isNull(nowVarValue))
					nowVarValue = "0";
				nowVarValue = String.valueOf(Float.valueOf(nowVarValue) + Float.valueOf(value));
			} else {
				if (Validator.isNull(nowVarValue))
					nowVarValue = "";
				nowVarValue = nowVarValue + prefix + value + spacer;
			}
			request.setAttribute(var, nowVarValue);
		} catch (Exception e) {
		}
		if (b) {
			return super.EVAL_BODY_INCLUDE;
		} else {
			return super.SKIP_BODY;
		}
	}

	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getVarType() {
		return varType;
	}

	public void setVarType(String varType) {
		this.varType = varType;
	}

	public String getSpacer() {
		return spacer;
	}

	public void setSpacer(String spacer) {
		this.spacer = spacer;
	}

	public String getPrefix() {
		return prefix;
	}

	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}

}
